home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / Matlab mode / matlabDoc.tcl < prev    next >
Encoding:
Text File  |  2000-05-10  |  4.5 KB  |  155 lines

  1. ################################################################################
  2. #
  3. # matlabDoc.tcl, part of the matlab mode package
  4. # Documentation system using matlab and web browser
  5. ################################################################################
  6.  
  7. proc matlabDoc.tcl {} {}
  8.  
  9. ################################################################################
  10. # Main proc for getting help.
  11. # Does both web and matlab help depending on modeVar webHelp.
  12. ################################################################################
  13.  
  14. proc getMatlabHelp {command} {
  15.     global MATLmodeVars
  16.     
  17.     if {$MATLmodeVars(webHelp)} {
  18.         set docURL [findMatlabHelpFile $command]
  19.         if {$docURL != ""} {
  20.             sendUrl "$docURL"
  21.             return
  22.         }
  23.     }
  24.     
  25.     set scriptName "help $command"
  26.     matlabDoScript $scriptName 2 0 {MATL::DocReplyHandler}
  27. }
  28.  
  29. ################################################################################ 
  30. # Return the path of help directory.
  31. # It can be set by the user in the preferences, but we will 
  32. # ask Matlab if we do not already know it.  
  33. ################################################################################
  34.  
  35. proc matlabHelpDir {} {
  36.     global MATLmodeVars modifiedModeVars
  37.     
  38.     if {![info exists MATLmodeVars(MatlabHelpFolder)] || [expr {$MATLmodeVars(MatlabHelpFolder) == ""}]} {
  39.         set MATLmodeVars(MatlabHelpFolder) [string trim [matlabDoScript disp(docroot) 0 1]]
  40. #         set MatlabHelpFolder [get_directory -p "Select Matlab help folder:"]
  41.         lappend modifiedModeVars {MatlabHelpFolder MATLmodeVars}
  42.     }
  43.     
  44.     return $MATLmodeVars(MatlabHelpFolder)
  45. }
  46.  
  47.  
  48. ################################################################################
  49. #  Get the URL of a help file
  50. ################################################################################
  51.  
  52. proc findMatlabHelpFile {command} {
  53.     
  54.     set helpDir [matlabHelpDir]
  55.     if {$helpDir != ""} {
  56.         set docPath "$helpDir:techdoc:ref:$command.html"
  57.         if {[file exists $docPath]} {
  58.             regsub  -all ":" $docPath "/" docPath
  59.             return "file:///$docPath"
  60.         }
  61.     }
  62.     
  63.     set mFile [matlabWhichFile $command]
  64.     if {$mFile == ""} {return -code return}
  65.     
  66.     set docPath "[file dirname $mFile]:html:$command.html"
  67.     if {[file exists $docPath]} {
  68.         regsub  -all ":" $docPath "/" docPath
  69.         return "file:///$docPath"
  70.     }
  71.     
  72.     return ""
  73. }
  74.  
  75.  
  76. ################################################################################
  77. #  Search MATLAB documentation
  78. ################################################################################
  79.  
  80. proc matlabSearchHelp {command} {
  81.     global MATLmodeVars
  82.  
  83.     if {$MATLmodeVars(webHelp)} {
  84.         set helpDir [matlabHelpDir]
  85.         if {$helpDir == ""} {return}
  86.         
  87.         regsub -all -- ":" $helpDir "/" docPath
  88.         regsub -all -- " " $command "+" command
  89.         set docURL "file:///$docPath/searchindex.html?searchnv=$command"
  90.         sendUrl "$docURL"
  91.     } else {
  92.         set scriptName "lookfor $command"
  93.         matlabDoScript $scriptName 2 0 MATL::DocReplyHandler
  94.     }
  95. }
  96.     
  97.  
  98. ################################################################################
  99. #  Create a new window with function definition
  100. ################################################################################
  101.  
  102. proc matlabShowDefinition {name def} {
  103.     new -n "* $name *" -m MATL
  104.     insertText $def
  105.     goto [minPos]
  106.  
  107.     # Set window mode to MATLAB, so that we can follow 
  108.     # cross-references by Cmd-dbl-clicking (and colors
  109.     # are active, etc...)
  110.     
  111. #     newMode MATL
  112.     catch {shrinkWindow 1}
  113.     set win [lindex [winNames -f] 0]
  114.     setWinInfo -w $win dirty 0
  115.     setWinInfo -w $win read-only 1
  116.  
  117. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
  118. #
  119. # ◊◊◊◊ UI procs for getting help ◊◊◊◊ #
  120. #
  121. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-
  122.  
  123. ################################################################################
  124. # Get help on selected command
  125. ################################################################################
  126.  
  127. proc matlabHelpSelection {} {
  128.     getMatlabHelp [getSelect]
  129. }
  130.  
  131.  
  132. ################################################################################
  133. #  Present a dialog to get help on a command
  134. ################################################################################
  135.  
  136. proc matlabHelp {} {
  137.     set text [getline "Enter command"]
  138.     if {$text == ""} {return}
  139.     getMatlabHelp $text
  140. }
  141.  
  142.  
  143. ################################################################################
  144. #  Present a dialog to search help on a command
  145. ################################################################################
  146.  
  147. proc matlabSearchHelpDialog {} {
  148.     set command [getline "Enter search string"]
  149.     if {$command == ""} {return}
  150.     matlabSearchHelp $command
  151. }
  152.